package com.qmth.dao;

import com.qmth.entity.Student;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * Created by zhengmin on 15-1-22.
 */
@Repository
public class JpaDao {

    @PersistenceContext
    private EntityManager em;

    public Integer getStudent() {
        Session session = (Session)em.getDelegate();
        Criteria crit = session.createCriteria(Student.class);
        Integer count = ((Number) crit.setProjection(Projections.rowCount()).uniqueResult()).intValue();
        return count;
    }

}
